<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('index');
});

Auth::routes(['reset' => false, 'verify' => false]);

Route::get('/home', 'HomeController@index')->name('home');
Route::prefix('dashboard')->namespace('Dashboard')->name('dashboard.')->middleware(['auth', \App\Http\Middleware\CanEnterDashboard::class])->group(function () {
    Route::get('/', 'DashboardHomeController')->name('home');
    Route::middleware([\App\Http\Middleware\CheckIsAdmin::class])->group(function () {

        Route::get('users/filters', 'UserController@filters')->name('users.filters');
        Route::resource('users', 'UserController');

        Route::get('careers/auto-complete', 'CareerController@autoComplete')->name('careers.auto_complete');

        Route::resource('careers', 'CareerController');

        Route::prefix('careers')->name('careers.skills.')->group(function () {
            Route::get('{career}/skills', 'CareerSkillController@skills')->name('index');
            Route::get('{career}/skills/{skill}', 'CareerSkillController@detail');
            Route::get('{career}/skills/{skill}/relation', 'CareerSkillController@relation')->name('relation');
            Route::post('{career}/skills/{skill}', 'CareerSkillController@attach')->name('attach');
            Route::post('{career}/skills/{skill}/next-skill', 'CareerSkillController@addNextSkill')->name('add-next-skill');
            Route::put('{career}/skills/{skill}', 'CareerSkillController@update')->name('update');
            Route::delete('{career}/skills/{skill}', 'CareerSkillController@detach')->name('detach');
            Route::delete('{career}/skills/{skill}/next-skill', 'CareerSkillController@deleteNextSkill')->name('delete-next-skill');
        });

        Route::get('skills/auto-complete', 'SkillController@autoComplete')->name('skills.auto_complete');
        Route::prefix('skills')->name('skills.courses.')->group(function () {
            Route::get('{skill}/courses', 'SkillCourseController@courses')->name('index');
            Route::get('{skill}/courses/{course}', 'SkillCourseController@detail');
            Route::get('{skill}/courses/{course}/relation', 'SkillCourseController@relation');
            Route::post('{skill}/courses/{course}', 'SkillCourseController@attach')->name('attach');
            Route::post('{skill}/courses/{course}/next-skill', 'SkillCourseController@addNextCourse')->name('add-next-course');
            Route::put('{skill}/courses/{course}', 'SkillCourseController@update')->name('update');
            Route::delete('{skill}/courses/{course}', 'SkillCourseController@detach')->name('detach');
            Route::delete('{skill}/courses/{course}/next-skill', 'SkillCourseController@deleteNextCourse')->name('delete-next-course');
        });
        Route::resource('skills', 'SkillController');
        Route::prefix('skills')->name('skills.careers.')->group(function () {
            Route::get('{skill}/careers', 'CareerSkillController@careers')->name('index');
        });

        Route::get('courses/auto-complete', 'CourseController@autoComplete')->name('courses.auto_complete');
        Route::prefix('courses/{course}/works')->name('courses.works.')->group(function () {
            Route::get('', 'WorkController@index')->name('index');
            Route::post('', 'WorkController@store')->name('store');

        });
        Route::resource('works', 'WorkController')->only([
            'show', 'update', 'delete'
        ]);
        Route::resource('courses', 'CourseController');

        Route::prefix('vod')->name('vod.')->group(function () {
            Route::get('play-info/{videoId}', 'AliyunVodController@getPlayInfo')->name('getPlayInfo');
            Route::get('upload/create', 'AliyunVodController@createUploadVideo')->name('createUploadVideo');
            Route::get('upload/refresh', 'AliyunVodController@refreshUploadVideo')->name('createUploadVideo');
        });
    });
    Route::get('user-work', 'UserWorkController@index')->name('user-work.index');
    Route::put('user-work', 'UserWorkController@update')->name('user-work.update');
});

Route::prefix('app')->namespace('App')->name('app.')->middleware(['auth', \App\Http\Middleware\CheckIsStudent::class])->group(function () {
    Route::any('', 'AppHomeController')->name('index');
    Route::prefix('careers')->name('careers.')->group(function () {
        Route::get('', 'CareerController@index')->name('index');
        Route::get('current', 'CareerController@current')->name('current');
        Route::get('previous', 'CareerController@previous')->name('previous');
        Route::get('{career}', 'CareerController@detail')->name('detail');

        Route::post('{career}', 'CareerController@select')->name('select');
        Route::delete('{career}', 'CareerController@forget')->name('forget');
    });
    Route::prefix('skills')->name('skills.')->group(function () {
//        Route::get('', 'SkillController@index')->name('index');
        Route::get('{skill}', 'SkillController@detail')->name('detail');

        Route::get('{skill}/courses/{course}/next', 'SkillCourseController@next')->name('courses.next');
    });
    Route::prefix('courses')->name('courses.')->group(function () {
//        Route::get('', 'SkillController@index')->name('index');
        Route::post('{course}/accumulate', 'CourseController@accumulate')->name('accumulate');
        Route::post('{course}/complete', 'CourseController@complete')->name('complete');
        Route::get('{course}', 'CourseController@detail')->name('detail');
        Route::get('{course}/works', 'WorkController@index')->name('works.index');

    });
    Route::post('works/upload', 'WorkController@upload')->name('works.upload');
    Route::post('works/{work}', 'WorkController@attach')->name('works.attach');

    Route::get('vod-play-info', 'VodPlayInfoController')->name('vodPlayInfo');
    Route::get('user/profile', 'UserController@profile')->name('user.profile');
});

